<template>
  <!--柱状图-->
  <div
    :style="{width:width,height:height}"
  ></div>
</template>

<script>
  export default {
    name: 'BarCharts',
    props: {
      width: {
        type: String,
        default: '100%'
      },
      height: {
        type: String,
        default: ''
      },
      /**
       * @param:
       *    dataLine  --> 折线的数据
       *    dataY  --> Y轴的数据
       * @date 2020/08/23
       * @author ZhuHongWei
       */
      chartData: {
        type: Object,
        default: () => {
        }
      }
    },
    data() {
      return {}
    },
    watch: {
      chartData: {
        deep: true,
        handler: function () {
          this.initChart()
        }
      }
    },
    mounted() {
      this.$nextTick(() => {
        this.initChart()
      })
    },
    methods: {
      initChart() {
        let that = this
        this.chart = this.$echarts.init(this.$el)
        this.chart.clear()
        let option = {
          color: ['#fccb05','#248ff7', '#8bd46e'],
          legend: {
            textStyle: {
              color: '#B4B4B4'
            },
            bottom: 0,
          },
          tooltip: {},
          dataset: {
            dimensions: this.chartData.dimensions,
            source: this.chartData.source
          },
          xAxis: {
            type: 'category',
            nameTextStyle: {
              color: '#FFFFFF',
              padding: [30, 0, 0, 0]
            },
            axisLabel: {
              textStyle: {
                color: "#FFFFFF",
                fontSize: 14
              },
            },
            axisLine: {
              show: true,
              lineStyle: {
                color: 'rgba(255,255,255,0.1)'
              }
            },
            axisTick: {
              show: true
            },
          },
          yAxis: {
            nameTextStyle: {
              color: '#FFFFFF',
              fontSize: 12,
              padding: [0,0,-20,-80]
            },
            splitLine: {
              lineStyle: {
                color: 'rgba(255,255,255,0.1)'
              }
            },
            axisLine: {
              show: true,
              lineStyle: {
                color: 'rgba(255,255,255,0.1)'
              }
            },
            axisLabel: {
              show: true,
              textStyle: {
                color: "#ffffff",
                fontSize: 14
              }
            },
          },
          series: [{ type: 'bar' }, { type: 'bar' }, { type: 'bar' }]
        }
        this.chart.setOption(option)
      }
    }
  }
</script>

<style scoped>
</style>
